import axios from 'axios';
import Vue from 'vue';

const baseURL = process.env.API_ROOT;


const request = axios.create({
  baseURL,
  timeout: 15 * 1000,
});

request.interceptors.request.use(
  (config) => {
    // const token = Vue.ls.get('access_token');
    const headers = {
      'Content-Type': 'application/json',
    };
    // console.log(`token`, token)
    // if (token) headers['token'] = token;
    config.headers = { ...config.headers, ...headers };
    return config;

  },
  (error) => {
    // notification.error({
    //   message: '系统提示',
    //   description: '网络请求失败',
    //   duration: 3,
    // });
    return Promise.reject(error);
  }
);

request.interceptors.response.use(
  (response) => {

    const { message, code, success } = response.data;
    return response.data;
  },
  (error) => {
    console.error(error);
      return Promise.reject(error.response);
  }
);

export default request;
